package com.pri.chat.activity;

import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.netease.nim.uikit.net.StatusBarUtil;
import com.pri.chat.R;
import com.pri.chat.base.BaseActivity;
import com.pri.chat.fragment.FriendsFragment;
import com.pri.chat.fragment.WishDoneFragment;
import com.pri.chat.fragment.WishMsgFragment;
import com.vondear.rxtool.RxActivityTool;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 描述：添加类的描述
 *
 * @author wx5e48d604c2885118
 * @time 2020/4/24
 */
public class MyFriendsActivity extends BaseActivity {
    @BindView(R.id.iv_returns)
    ImageView iv_returns;
    @BindView(R.id.stl_wish)
    SlidingTabLayout stlWish;
    @BindView(R.id.vp_wish)
    ViewPager vpWish;
    private String[] mTitle = new String[]{"我的粉丝", "关注的人", "我的好友"};

    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_friends_layout;
    }

    private int selectIndex = 0;

    @Override
    protected void initView() {
        setTitle("关注");
        Bundle bundle = getIntent().getExtras();
        int type = bundle.getInt("type");
        ArrayList<Fragment> arrayList = new ArrayList<>();
        arrayList.add(FriendsFragment.getInstance(0));
        arrayList.add(FriendsFragment.getInstance(1));
        arrayList.add(FriendsFragment.getInstance(2));
        stlWish.setViewPager(vpWish, mTitle, this, arrayList);

        stlWish.getTitleView(type).setTextSize(20);
        if(type == 0){
            stlWish.getTitleView(0).setTextSize(20);
            stlWish.getTitleView(1).setTextSize(14);
            stlWish.getTitleView(2).setTextSize(14);
        }else if(type == 1){
            stlWish.getTitleView(0).setTextSize(14);
            stlWish.getTitleView(1).setTextSize(20);
            stlWish.getTitleView(2).setTextSize(14);
        }else if(type == 2){
            stlWish.getTitleView(0).setTextSize(14);
            stlWish.getTitleView(1).setTextSize(14);
            stlWish.getTitleView(2).setTextSize(20);
        }
        stlWish.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                for (int i = 0; i < arrayList.size(); i++) {
                    if (i == position) {
                        stlWish.getTitleView(position).setTextSize(20);
                        stlWish.getTitleView(position).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    } else {
                        stlWish.getTitleView(i).setTextSize(14);
                        stlWish.getTitleView(i).setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                    }
                }

            }

            @Override
            public void onTabReselect(int position) {

            }
        });


        vpWish.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                selectIndex = position;
                for (int i = 0; i < arrayList.size(); i++) {
                    if (i == position) {
                        stlWish.getTitleView(position).setTextSize(20);
                        stlWish.getTitleView(position).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    } else {
                        stlWish.getTitleView(i).setTextSize(14);
                        stlWish.getTitleView(i).setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        stlWish.setCurrentTab(type);
        selectIndex = type;
        stlWish.getTitleView(selectIndex).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.iv_returns)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);

        View view = findViewById(R.id.rl_center1);
        StatusBarUtil.setColor(this, getResources().getColor(R.color.white), 0);
        StatusBarUtil.setTranslucentForImageViewInFragment(this, 0, view);
        StatusBarUtil.setLightMode(this);
    }
}
